//
//  ViewController.swift
//  Center
//
//  Created by Pro on 2019/7/26.
//  Copyright © 2019 Pro. All rights reserved.
//

import UIKit
import RxCocoa
import RxSwift


class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let ob = Observable<Any>.create { (obserber) -> Disposable in
            obserber.onNext("订阅到了这里的信息")
            obserber.onCompleted()
//            obserber.onError(NSError.init(domain: "me error", code: 10086, userInfo: nil))
            return Disposables.create()
        }
        
        let _ = ob.subscribe(onNext: { (text) in
            print("订阅到：\(text)")
        }, onError: { (err) in
            print(err)
        }, onCompleted: {
            print("完成")
        }) {
            print("销毁")
        }
    }


}

//代码内容

//Observable：ObservableType：ObservableConvertibleType


//先说ObservableConvertibleType属于协议，有协议方法asObservable

//associatedtype Element
//
//@available(*, deprecated, message: "Use `Element` instead.")
//typealias E = Element
//
///// Converts `self` to `Observable` sequence.
/////
///// - returns: Observable sequence that represents `self`.
//func asObservable() -> Observable<Element>


//再说 ObservableType 也是协议，有协议方法：
 //func subscribe<Observer: ObserverType>(_ observer: Observer) -> Disposable where Observer.Element == Element

//最后说：Observable 这是一个class,有类方法可以执行
//public func subscribe<Observer: ObserverType>(_ observer: Observer) -> Disposable where Observer.Element == Element {
//    rxAbstractMethod()
//}
//
//public func asObservable() -> Observable<Element> {
//    return self
//}

//由这里可以看到Observable的subscribe方法来源于父类的ObservableType
//Observable的 asObservable()方法来源于ObservableConvertibleType
